package EA;
import EA.testproblems.*; 

public class DiscreteRNumFramework extends RealNumericalFramework
{
  /** Discrete stepsizes to impose on genomes. */
  public double[] discrete_stepsize; 

  /** The number of steps per variable. Can for instance be used to 
      iterate over the search space. Entries contain zero if stepsize is
      zero.
  */
  public int[] steps_per_variable;

  /** Create a new DiscreteRNumFramework. This used when the framework is 
      just used to access implementation dependent variables.
  */
  public DiscreteRNumFramework()
    {
      super();
    }


  /** Create a new DiscreteRNumFramework. */
  public DiscreteRNumFramework(Fitness ffunction)
    {
    super(ffunction);
    }

  /** Create a new DiscreteRNumFramework. */
  public DiscreteRNumFramework(int thedimensions, Fitness ffunction)
    {
      super(thedimensions, ffunction);
      discrete_stepsize = new double[thedimensions];
    }
  
  public DiscreteRNumFramework(int thedimensions, Interval[] theintervals, Fitness ffunction)
    {
      super(thedimensions, theintervals, ffunction);
      discrete_stepsize = new double[thedimensions];
      steps_per_variable = new int[thedimensions];
    }

  
  /** Create a new DiscreteRNumFramework. This used when the genome is 
      just used to model a number of variables.
  */
  public DiscreteRNumFramework(int thedimensions, Interval[] theintervals)
    {
      super(thedimensions, theintervals);
      discrete_stepsize = new double[thedimensions];
      steps_per_variable = new int[thedimensions];
    }

  /** Create a new DiscreteRNumFramework.
      @param IP Value of the intervalpartition.
  */
  public DiscreteRNumFramework(int thedimensions, Interval[] theintervals, Fitness ffunction, double IP)
    {
      super(thedimensions, theintervals, ffunction, IP);
      discrete_stepsize = new double[thedimensions];
      steps_per_variable = new int[thedimensions];
    }

  /** Create a new DiscreteRNumFramework.
  */
  public DiscreteRNumFramework(NumericalProblem numproblem)
    {
      super(numproblem);
      discrete_stepsize = new double[dimensions];
      steps_per_variable = new int[dimensions];
    }

  /** Create a new DiscreteRNumFramework.
      @param IP Value of the intervalpartition.
  */
  public DiscreteRNumFramework(NumericalProblem numproblem, double IP)
    {
      super(numproblem, IP);
      discrete_stepsize = new double[dimensions];
      steps_per_variable = new int[dimensions];
    }

  /** Create a new DiscreteRNumFramework.
      @param stepsizes The discrete stepsizes for this framework.
  */
  public DiscreteRNumFramework(NumericalProblem numproblem, double[] stepsizes)
    {
      super(numproblem);
      setDiscreteStepsize(stepsizes);
    }

  /** Create a new DiscreteRNumFramework.
      @param IP Value of the intervalpartition.
      @param stepsizes The discrete stepsizes for this framework.
  */
  public DiscreteRNumFramework(NumericalProblem numproblem, double IP, double[] stepsizes)
    {
      super(numproblem, IP);
      setDiscreteStepsize(stepsizes);
    }


  /** Set the discrete stepsizes. <tt>stepsizes</tt> is copied by
      reference, i.e., not value by value.
  */
  public void setDiscreteStepsize(double[] stepsizes)
    {
      int i;

      discrete_stepsize = stepsizes;
      steps_per_variable = new int[discrete_stepsize.length];

      for (i=0;i<steps_per_variable.length;i++) {
	if (discrete_stepsize[i]!=0) {
	  steps_per_variable[i] = 1+(int)Math.rint(intervals[i].getLength()/discrete_stepsize[i]);
	}
	else {
	  steps_per_variable[i] = 0;
	}
      }
    }

}
